home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.plaf.basic;
-
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.Window;
- import java.awt.event.InputEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.beans.PropertyChangeListener;
- import java.util.EventObject;
- import javax.swing.BorderFactory;
- import javax.swing.BoxLayout;
- import javax.swing.ComboBoxModel;
- import javax.swing.JComboBox;
- import javax.swing.JComponent;
- import javax.swing.JDialog;
- import javax.swing.JList;
- import javax.swing.JPopupMenu;
- import javax.swing.JRootPane;
- import javax.swing.JScrollPane;
- import javax.swing.ListCellRenderer;
- import javax.swing.MenuElement;
- import javax.swing.MenuSelectionManager;
- import javax.swing.SwingUtilities;
- import javax.swing.Timer;
- import javax.swing.UIManager;
- import javax.swing.border.Border;
- import javax.swing.event.ListDataListener;
- import javax.swing.event.ListSelectionListener;
-
- public class BasicComboPopup extends JPopupMenu implements ComboPopup {
- protected JComboBox comboBox;
- protected JList list;
- protected JScrollPane scroller;
- protected boolean valueIsAdjusting = false;
- protected MouseMotionListener mouseMotionListener;
- protected MouseListener mouseListener;
- protected KeyListener keyListener;
- protected ListSelectionListener listSelectionListener;
- protected ListDataListener listDataListener;
- protected MouseListener listMouseListener;
- protected MouseMotionListener listMouseMotionListener;
- protected PropertyChangeListener propertyChangeListener;
- protected ItemListener itemListener;
- protected Timer autoscrollTimer;
- protected boolean hasEntered = false;
- protected boolean isAutoScrolling = false;
- protected int scrollDirection = 0;
- protected static final int SCROLL_UP = 0;
- protected static final int SCROLL_DOWN = 1;
- private boolean lightNav = false;
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION = "JComboBox.lightweightKeyboardNavigation";
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION_ON = "Lightweight";
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION_OFF = "Heavyweight";
-
- public BasicComboPopup(JComboBox var1) {
- this.comboBox = var1;
- Object var2 = ((JComponent)var1).getClientProperty("JComboBox.lightweightKeyboardNavigation");
- if (var2 != null) {
- if (var2.equals("Lightweight")) {
- this.lightNav = true;
- } else if (var2.equals("Heavyweight")) {
- this.lightNav = false;
- }
- }
-
- this.mouseListener = this.createMouseListener();
- this.mouseMotionListener = this.createMouseMotionListener();
- this.keyListener = this.createKeyListener();
- this.listSelectionListener = this.createListSelectionListener();
- this.listDataListener = this.createListDataListener();
- this.listMouseListener = this.createListMouseListener();
- this.listMouseMotionListener = this.createListMouseMotionListener();
- this.propertyChangeListener = this.createPropertyChangeListener();
- this.itemListener = this.createItemListener();
- this.list = this.createList();
- this.configureList();
- this.scroller = this.createScroller();
- this.configureScroller();
- this.configurePopup();
- this.installComboBoxListeners();
- this.installKeyboardActions();
- }
-
- // $FF: synthetic method
- static boolean access$0(BasicComboPopup var0) {
- return var0.lightNav;
- }
-
- // $FF: synthetic method
- static void access$1(BasicComboPopup var0, boolean var1) {
- var0.lightNav = var1;
- }
-
- protected void autoScrollDown() {
- int var1 = this.list.getSelectedIndex();
- int var2 = this.list.getModel().getSize() - 1;
- if (var1 < var2) {
- this.valueIsAdjusting = true;
- this.list.setSelectedIndex(var1 + 1);
- this.valueIsAdjusting = false;
- this.list.ensureIndexIsVisible(var1 + 1);
- }
-
- }
-
- protected void autoScrollUp() {
- int var1 = this.list.getSelectedIndex();
- if (var1 > 0) {
- this.valueIsAdjusting = true;
- this.list.setSelectedIndex(var1 - 1);
- this.valueIsAdjusting = false;
- this.list.ensureIndexIsVisible(var1 - 1);
- }
-
- }
-
- protected Rectangle computePopupBounds(int var1, int var2, int var3, int var4) {
- Rectangle var6 = new Rectangle(var1, var2, var3, var4);
- boolean var7 = this.inModalDialog();
- Rectangle var5;
- if (var7) {
- Dialog var8 = this.getDialog();
- if (var8 instanceof JDialog) {
- JRootPane var10 = ((JDialog)var8).getRootPane();
- Point var9 = ((Component)var10).getLocationOnScreen();
- var5 = ((Component)var10).getBounds();
- var5.x = var9.x;
- var5.y = var9.y;
- } else {
- var5 = ((Component)var8).getBounds();
- }
-
- Point var13 = new Point(var5.x, var5.y);
- SwingUtilities.convertPointFromScreen(var13, this.comboBox);
- var5.x = var13.x;
- var5.y = var13.y;
- } else {
- Dimension var14 = Toolkit.getDefaultToolkit().getScreenSize();
- var5 = new Rectangle();
- Point var11 = new Point(0, 0);
- SwingUtilities.convertPointFromScreen(var11, this.comboBox);
- var5.x = var11.x;
- var5.y = var11.y;
- var5.width = var14.width;
- var5.height = var14.height;
- }
-
- if (SwingUtilities.isRectangleContainingRectangle(var5, var6)) {
- return var6;
- } else {
- Rectangle var12 = new Rectangle(0, -var6.height, var6.width, var6.height);
- if (SwingUtilities.isRectangleContainingRectangle(var5, var12)) {
- return var12;
- } else if (var7) {
- SwingUtilities.computeIntersection(var5.x, var5.y, var5.width, var5.height, var6);
- SwingUtilities.computeIntersection(var5.x, var5.y, var5.width, var5.height, var12);
- return var6.height > var12.height ? var6 : var12;
- } else {
- return var12;
- }
- }
- }
-
- protected void configureList() {
- this.list.setFont(this.comboBox.getFont());
- this.list.setForeground(this.comboBox.getForeground());
- this.list.setBackground(this.comboBox.getBackground());
- this.list.setSelectionForeground(UIManager.getColor("ComboBox.selectionForeground"));
- this.list.setSelectionBackground(UIManager.getColor("ComboBox.selectionBackground"));
- this.list.setBorder((Border)null);
- this.list.setCellRenderer(this.comboBox.getRenderer());
- this.list.setRequestFocusEnabled(false);
- this.syncListSelectionWithComboBoxSelection();
- this.list.setSelectionMode(0);
- this.installListListeners();
- }
-
- protected void configurePopup() {
- ((Container)this).setLayout(new BoxLayout(this, 1));
- ((JPopupMenu)this).setBorderPainted(true);
- ((JComponent)this).setBorder(BorderFactory.createLineBorder(Color.black));
- ((JComponent)this).setOpaque(false);
- ((Container)this).add(this.scroller);
- ((JComponent)this).setDoubleBuffered(true);
- ((JComponent)this).setRequestFocusEnabled(false);
- }
-
- protected void configureScroller() {
- this.scroller.setRequestFocusEnabled(false);
- this.scroller.getVerticalScrollBar().setRequestFocusEnabled(false);
- this.scroller.setBorder((Border)null);
- }
-
- protected MouseEvent convertMouseEvent(MouseEvent var1) {
- Point var2 = SwingUtilities.convertPoint((Component)((EventObject)var1).getSource(), var1.getPoint(), this.list);
- MouseEvent var3 = new MouseEvent((Component)((EventObject)var1).getSource(), ((AWTEvent)var1).getID(), ((InputEvent)var1).getWhen(), ((InputEvent)var1).getModifiers(), var2.x, var2.y, ((InputEvent)var1).getModifiers(), var1.isPopupTrigger());
- return var3;
- }
-
- protected ItemListener createItemListener() {
- return new ItemHandler(this);
- }
-
- protected KeyListener createKeyListener() {
- return new InvocationKeyHandler(this);
- }
-
- protected JList createList() {
- return new JList(this.comboBox.getModel());
- }
-
- protected ListDataListener createListDataListener() {
- return new ListDataHandler(this);
- }
-
- protected MouseListener createListMouseListener() {
- return new ListMouseHandler(this);
- }
-
- protected MouseMotionListener createListMouseMotionListener() {
- return new ListMouseMotionHandler(this);
- }
-
- protected ListSelectionListener createListSelectionListener() {
- return new ListSelectionHandler(this);
- }
-
- protected MouseListener createMouseListener() {
- return new InvocationMouseHandler(this);
- }
-
- protected MouseMotionListener createMouseMotionListener() {
- return new InvocationMouseMotionHandler(this);
- }
-
- protected PropertyChangeListener createPropertyChangeListener() {
- return new PropertyChangeHandler(this);
- }
-
- protected JScrollPane createScroller() {
- return new JScrollPane(this.list, 20, 31);
- }
-
- protected void delegateFocus(MouseEvent var1) {
- if (this.comboBox.isEditable()) {
- this.comboBox.getEditor().getEditorComponent().requestFocus();
- } else {
- this.comboBox.requestFocus();
- }
-
- }
-
- private Dialog getDialog() {
- Container var1;
- for(var1 = this.comboBox.getParent(); var1 != null && !(var1 instanceof Dialog) && !(var1 instanceof Window); var1 = ((Component)var1).getParent()) {
- }
-
- return var1 instanceof Dialog ? (Dialog)var1 : null;
- }
-
- public KeyListener getKeyListener() {
- return this.keyListener;
- }
-
- public JList getList() {
- return this.list;
- }
-
- public MouseListener getMouseListener() {
- return this.mouseListener;
- }
-
- public MouseMotionListener getMouseMotionListener() {
- return this.mouseMotionListener;
- }
-
- protected int getPopupHeightForRowCount(int var1) {
- int var2 = this.comboBox.getModel().getSize();
- int var3 = Math.min(var1, var2);
- int var4 = 0;
- ListCellRenderer var5 = this.list.getCellRenderer();
- Object var6 = null;
-
- for(int var7 = 0; var7 < var3; ++var7) {
- var6 = this.list.getModel().getElementAt(var7);
- Component var8 = var5.getListCellRendererComponent(this.list, var6, var7, false, false);
- var4 += var8.getPreferredSize().height;
- }
-
- return var4 == 0 ? 100 : var4;
- }
-
- public void hide() {
- MenuSelectionManager var1 = MenuSelectionManager.defaultManager();
- MenuElement[] var2 = var1.getSelectedPath();
-
- for(int var3 = 0; var3 < var2.length; ++var3) {
- if (var2[var3] == this) {
- var1.clearSelectedPath();
- break;
- }
- }
-
- this.comboBox.repaint();
- }
-
- private boolean inModalDialog() {
- return this.getDialog() != null;
- }
-
- protected void installComboBoxListeners() {
- this.comboBox.addPropertyChangeListener(this.propertyChangeListener);
- this.comboBox.addItemListener(this.itemListener);
- this.installComboBoxModelListeners(this.comboBox.getModel());
- }
-
- protected void installComboBoxModelListeners(ComboBoxModel var1) {
- if (var1 != null) {
- var1.addListDataListener(this.listDataListener);
- }
-
- }
-
- protected void installKeyboardActions() {
- }
-
- protected void installListListeners() {
- this.list.addListSelectionListener(this.listSelectionListener);
- this.list.addMouseMotionListener(this.listMouseMotionListener);
- this.list.addMouseListener(this.listMouseListener);
- }
-
- public boolean isFocusTraversable() {
- return false;
- }
-
- public void show() {
- Dimension var1 = this.comboBox.getSize();
- var1.setSize(var1.width, this.getPopupHeightForRowCount(this.comboBox.getMaximumRowCount()));
- Rectangle var2 = this.computePopupBounds(0, this.comboBox.getBounds().height, var1.width, var1.height);
- this.scroller.setMaximumSize(var2.getSize());
- this.scroller.setPreferredSize(var2.getSize());
- this.scroller.setMinimumSize(var2.getSize());
- this.list.invalidate();
- this.syncListSelectionWithComboBoxSelection();
- this.list.ensureIndexIsVisible(this.list.getSelectedIndex());
- ((JPopupMenu)this).setLightWeightPopupEnabled(this.comboBox.isLightWeightPopupEnabled());
- ((JPopupMenu)this).show(this.comboBox, var2.x, var2.y);
- }
-
- protected void startAutoScrolling(int var1) {
- if (this.isAutoScrolling) {
- this.autoscrollTimer.stop();
- }
-
- this.isAutoScrolling = true;
- if (var1 == 0) {
- this.scrollDirection = 0;
- Point var2 = SwingUtilities.convertPoint(this.scroller, new Point(1, 1), this.list);
- int var3 = this.list.locationToIndex(var2);
- this.valueIsAdjusting = true;
- this.list.setSelectedIndex(var3);
- this.valueIsAdjusting = false;
- 1 var4 = new 1(this);
- this.autoscrollTimer = new Timer(100, var4);
- } else if (var1 == 1) {
- this.scrollDirection = 1;
- Dimension var6 = this.scroller.getSize();
- Point var7 = SwingUtilities.convertPoint(this.scroller, new Point(1, var6.height - 1 - 2), this.list);
- int var8 = this.list.locationToIndex(var7);
- this.valueIsAdjusting = true;
- this.list.setSelectedIndex(var8);
- this.valueIsAdjusting = false;
- 2 var5 = new 2(this);
- this.autoscrollTimer = new Timer(100, var5);
- }
-
- this.autoscrollTimer.start();
- }
-
- protected void stopAutoScrolling() {
- this.isAutoScrolling = false;
- if (this.autoscrollTimer != null) {
- this.autoscrollTimer.stop();
- this.autoscrollTimer = null;
- }
-
- }
-
- void syncListSelectionWithComboBoxSelection() {
- int var1 = this.comboBox.getSelectedIndex();
- if (var1 == -1) {
- this.list.clearSelection();
- } else {
- this.list.setSelectedIndex(var1);
- }
-
- }
-
- protected void togglePopup() {
- if (((JPopupMenu)this).isVisible()) {
- this.hide();
- } else {
- this.show();
- }
-
- }
-
- protected void uninstallComboBoxModelListeners(ComboBoxModel var1) {
- if (var1 != null) {
- var1.removeListDataListener(this.listDataListener);
- }
-
- }
-
- protected void uninstallKeyboardActions() {
- }
-
- public void uninstallingUI() {
- this.comboBox.removePropertyChangeListener(this.propertyChangeListener);
- this.comboBox.removeItemListener(this.itemListener);
- this.uninstallComboBoxModelListeners(this.comboBox.getModel());
- this.uninstallKeyboardActions();
- }
-
- protected void updateListBoxSelectionForEvent(MouseEvent var1, boolean var2) {
- Point var3 = var1.getPoint();
- if (this.list != null) {
- int var4 = this.list.locationToIndex(var3);
- if (var4 == -1) {
- if (var3.y < 0) {
- var4 = 0;
- } else {
- var4 = this.comboBox.getModel().getSize() - 1;
- }
- }
-
- if (this.list.getSelectedIndex() != var4) {
- this.list.setSelectedIndex(var4);
- if (var2) {
- this.list.ensureIndexIsVisible(var4);
- }
- }
-
- }
- }
- }
-